package com.aos.erp.schools.rest.student;

import com.aos.erp.common.bean.PageBean;
import com.aos.erp.common.bean.ResultEntity;
import com.aos.erp.schools.cutils.TimeUtils;
import com.aos.erp.schools.cutils.router.Rest;
import com.aos.erp.schools.model.gatherschool.entity.GatherSchool;
import com.aos.erp.schools.model.student.ro.student.SelectByStateRo;
import com.aos.erp.schools.model.student.vo.field.StudentFieldVo;
import com.aos.erp.schools.model.student.vo.student.StudentEaxmVo;
import com.aos.erp.schools.service.student.StudentFieldService;
import com.aos.erp.schools.util.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: chb
 * @Date: 2018/11/1 19:22
 * @Description:    学员成绩
 */
@RestController
@RequestMapping(Rest.Field.ROOT)
@Api(tags = {"学员成绩"})
public class StudentFieldController {

    @Autowired
    private StudentFieldService studentFieldService;

    @GetMapping(Rest.Field.queryByStateK1)
    @ApiOperation(value = "科目一学员")
    public ResultEntity<PageBean<StudentFieldVo>> queryByStateK1(SelectByStateRo ro) {
        try {
            if (StringUtils.isEmpty(ro.getCurrentUserId())) {
                return ResultEntity.failed("请重新登录", ResultEntity.CODE_NULL);
            }
            GatherSchool driversSchool= UserUtil.getUserSchool(ro.getCurrentUserId());
            if(driversSchool==null){
                return ResultEntity.failed("驾校数据不存在");
            }
            ro.setSubject(1);//科目
            ro.setStatus(1);//科目三在培中
            ro.setTimeStartName(TimeUtils.start(ro.getTimeStart()));
            ro.setTimeEddName(TimeUtils.edd(ro.getTimeEdd()));
            PageBean<StudentFieldVo> student = studentFieldService.queryFieldBySubject(ro);
            return ResultEntity.success(student);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed("科目一学员成绩查询失败!");
        }
    }


    @GetMapping(Rest.Field.queryByStateK2)
    @ApiOperation(value = "科目二学员")
    public ResultEntity<PageBean<StudentFieldVo>> queryByStateK2(SelectByStateRo ro) {
        try {
            if (StringUtils.isEmpty(ro.getCurrentUserId())) {
                return ResultEntity.failed("请重新登录", ResultEntity.CODE_NULL);
            }
            GatherSchool driversSchool= UserUtil.getUserSchool(ro.getCurrentUserId());
            if(driversSchool==null){
                return ResultEntity.failed("驾校数据不存在");
            }
            ro.setSubject(2);
            ro.setStatus(2);//科目三在培中
            ro.setTimeStartName(TimeUtils.start(ro.getTimeStart()));
            ro.setTimeEddName(TimeUtils.edd(ro.getTimeEdd()));
            PageBean<StudentFieldVo> student = studentFieldService.queryFieldBySubject(ro);
            return ResultEntity.success(student);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed("科目二学员成绩查询失败!");
        }
    }


    @GetMapping(Rest.Field.queryByStateK3)
    @ApiOperation(value = "科目三学员")
    public ResultEntity<PageBean<StudentFieldVo>> queryByStateK3(SelectByStateRo ro) {
        try {

            if (StringUtils.isEmpty(ro.getCurrentUserId())) {
                return ResultEntity.failed("请重新登录", ResultEntity.CODE_NULL);
            }
            GatherSchool driversSchool= UserUtil.getUserSchool(ro.getCurrentUserId());
            if(driversSchool==null){
                return ResultEntity.failed("驾校数据不存在");
            }
            ro.setSubject(3);
            ro.setStatus(3);//科目三在培中
            ro.setTimeStartName(TimeUtils.start(ro.getTimeStart()));
            ro.setTimeEddName(TimeUtils.edd(ro.getTimeEdd()));
            PageBean<StudentFieldVo> student = studentFieldService.queryFieldBySubject(ro);
            return ResultEntity.success(student);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed("科目三学员成绩查询失败!");
        }
    }

    @GetMapping(Rest.Field.queryByStateK4)
    @ApiOperation(value = "科目四学员")
    public ResultEntity<PageBean<StudentFieldVo>> queryByStateK4(SelectByStateRo ro) {
        try {
            if (StringUtils.isEmpty(ro.getCurrentUserId())) {
                return ResultEntity.failed("请重新登录", ResultEntity.CODE_NULL);
            }
            GatherSchool driversSchool= UserUtil.getUserSchool(ro.getCurrentUserId());
            if(driversSchool==null){
                return ResultEntity.failed("驾校数据不存在");
            }
            ro.setSubject(4);
            ro.setStatus(4);//科目四在培中
            ro.setTimeStartName(TimeUtils.start(ro.getTimeStart()));
            ro.setTimeEddName(TimeUtils.edd(ro.getTimeEdd()));
            PageBean<StudentFieldVo> student = studentFieldService.queryFieldBySubject(ro);
            return ResultEntity.success(student);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed("科目四学员成绩查询失败!");
        }
    }

}
